package squares;

import java.util.ArrayList;
import java.util.Random;

/**
 * a class that contains information about squares you can teleport by using this teleportation object.
 * @invar	there may be no duplicated squares in this teleportableSquares.
 * 			|for(Square square:teleportableSquares)
 * 			| 	teleportableSquares.indexOf(square) == teleportableSquares.lastIndexOf(square)
 * @version 1.0
 * @author Gilles Groven & Jochen Tombal
 */
public class Teleportation {
	
	private ArrayList<Square> teleportableSquares;
	private boolean teleportPossible;
	/**
	 * constructs a new teleportation with its fields initialized. and if teleportation is activated
	 * @param teleportPossible
	 * 		says if  teleportation is possible
	 * @post
	 * 		the teleportableSquares are empty
	 * 		| TeleporatationSquares.isEmpty()
	 * @post the given state of teleportPossible is the new state of teleportPossible.
	 * 		| new.teleportPossible() == teleportPossible
	 * */
	public Teleportation(boolean teleportPossible)
	{
		teleportableSquares = new ArrayList<Square>();
		this.teleportPossible = teleportPossible;
	}
	/**
	 * adds a new square to the teleportable square of this teleporation 
	 * @param square
	 * 		the square you want to be able to teleport to.
	 * @pre
	 * 		the square doensn't already exists
	 * 		|!teleportableSquares.contains(square)
	 * @post
	 * 		the square is added to the teleportable squares
	 * 		| new.getteleportableSquares().contains(square)
	 */
	public void addTeleportableSquare(Square square)
	{
		assert(!teleportableSquares.contains(square));
		this.teleportableSquares.add(square);
	}
	/**
	 * @return
	 * 	 	returns a clone of the teleportable squares of this teleportation
	 * 		| result == teleportableSquares.clone()
	 */
	@SuppressWarnings("unchecked")
	public ArrayList<Square> getTeleportableSquares()
	{
		return (ArrayList<Square>) teleportableSquares.clone();
	}
	/**
	 * removes the given square out of the teleportable squares
	 * @param square
	 * 		the square you want to remove.
	 * @pre
	 * 		the square has to be present as teleportable square
	 * 		| teleportableSquares.contains(square)
	 * @post
	 * 		the square is no longer present in the teleportablelist
	 * 		| !teleportableSquares.contains(square)
	 */
	public void removeTeleportableSquare(Square square)
	{
		assert(teleportableSquares.contains(square));
		this.teleportableSquares.remove(square);
		
	}
	/**
	 * 
	 * @return
	 * 		a random chosen square you can teleport to
	 * 		| this.teleportableSquares.contains(result)
	 */
	public Square getRandomTeleportableSquare()
	{
		Random choice = new Random();
		return teleportableSquares.get(choice.nextInt(teleportableSquares.size()-1));
	}
	/**
	 * changes the teleport capability of this teleportation
	 * @param possible
	 * 		a boolean to state if teleport is enabled or disabled
	 * @post 
	 * 		the new teleport capability is equal to the given value
	 * 		| teleportPossible == possible
	 */
	public void setIfTeleportPossible(Boolean possible)
	{
		this.teleportPossible = possible;
	}
	/**
	 * 
	 * @return
	 * 		the teleport capability of this teleporation.
	 */
	public boolean teleportPossible()
	{
		return this.teleportPossible;
	}
	/**
	 * 
	 * @return
	 * 		a copy of the arraylist containing all the teleportable squares.
	 */
	@SuppressWarnings("unchecked")
	public ArrayList<Square> getTeleportableSquaresList()
	{
		return (ArrayList<Square>) this.teleportableSquares.clone();
	}
}
